package leetcodecompetition.S114AC;

import java.util.List;

/**
 * @Author: Siantar
 * @Date: 2023-09-30-22:30
 * @Description: 1.0
 */
public class T8038 {
    public int minOperations(List<Integer> nums, int k) {
        int sum = 0;
        boolean[] bs = new boolean[k];
        int n = nums.size();
        for (int i = n - 1; i >= 0; i--) {
            int num = nums.get(i);
            if (num <= k && !bs[num - 1]) {
                bs[num - 1] = true;
                sum++;
                if (sum == k) {
                    return n - i;
                }
            }
        }
        return -1;
    }
}
